package com.example.skycode6.servlet;

import com.example.skycode6.dao.NewsDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/adminDel.jsp")
public class AdminDel extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
int id = Integer.parseInt(req.getParameter("AdminID"));
int result = (new NewsDao()).deleteNewsByNewsID(id);
if (result > 0) {//成功重新跳转到新闻页面
resp.sendRedirect("admin.jsp");
}else {//失败跳转错误页面 显示错误信息 并回到指定页面
req.setAttribute("msg","删除失败");
req.setAttribute("url","news.jsp");
req.getRequestDispatcher("WEB-INF/error.jsp").forward(req, resp);
}
}
}